{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "22a0b426",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Private Key: 40871478222817722377012551921323657605236631423958081783403470740144884256441\n",
      "Public Key: (18814187692496112820586797121940816605467606938301853840004393937958984136992, 72833048843328294920821861725991661253504985018641366317346599320677055943891)\n"
     ]
    }
   ],
   "source": [
    "# secp256k1 生成公钥\n",
    "# 利用标量乘法，从私钥生成公钥\n",
    "from py_ecc.secp256k1 import secp256k1\n",
    "import os \n",
    "\n",
    "def generate_public_key(private_key):\n",
    "    \"\"\"\n",
    "    使用secp256k1椭圆曲线，根据给定的私钥生成公钥。\n",
    "    \n",
    "    参数:\n",
    "    private_key (int): 私钥，一个大整数。\n",
    "    \n",
    "    返回:\n",
    "    (int, int): 公钥，椭圆曲线上的点。\n",
    "    \"\"\"\n",
    "    # secp256k1的基点\n",
    "    G = secp256k1.G\n",
    "    \n",
    "    # 计算公钥\n",
    "    public_key = secp256k1.multiply(G, private_key)\n",
    "    \n",
    "    return public_key\n",
    "\n",
    "# 示例：使用一个随机的私钥\n",
    "private_key = int(os.urandom(32).hex(), 16)\n",
    "\n",
    "# 生成公钥\n",
    "public_key = generate_public_key(private_key)\n",
    "\n",
    "# 打印结果\n",
    "print(f\"Private Key: {private_key}\")\n",
    "print(f\"Public Key: {public_key}\")\n",
    "\n",
    "# 示例输出\n",
    "# Private Key: 40871478222817722377012551921323657605236631423958081783403470740144884256441\n",
    "# Public Key: (18814187692496112820586797121940816605467606938301853840004393937958984136992, 72833048843328294920821861725991661253504985018641366317346599320677055943891)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d0f2379f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Private Key: 100160191408028635805410835424804882729758587641862022398559246101084514055515\n",
      "Public Key: (94753041202778772959486517607721465828067708966050249355074253521404789962176, 108824044826657285606250531715029407748756362423778933890891533480553307901806)\n",
      "Signature valid: True\n"
     ]
    }
   ],
   "source": [
    "# secp256k1 数字签名\n",
    "from py_ecc.secp256k1 import secp256k1\n",
    "import os\n",
    "import hashlib\n",
    "\n",
    "def sign_message(private_key, message):\n",
    "    \"\"\"\n",
    "    使用私钥对消息进行签名。\n",
    "    \"\"\"\n",
    "    message_hash = hashlib.sha256(message.encode()).digest()\n",
    "    private_key_bytes = private_key.to_bytes(32, \"big\")\n",
    "    signature = secp256k1.ecdsa_raw_sign(message_hash, private_key_bytes)\n",
    "    return signature\n",
    "\n",
    "def verify_signature(message, signature, public_key):\n",
    "    \"\"\"\n",
    "    使用公钥验证消息的签名。\n",
    "    \"\"\"\n",
    "    message_hash = hashlib.sha256(message.encode()).digest()\n",
    "    recovered_public_key = secp256k1.ecdsa_raw_recover(message_hash, signature)\n",
    "    return recovered_public_key == public_key\n",
    "\n",
    "# 示例使用\n",
    "private_key = int.from_bytes(os.urandom(32), 'big')\n",
    "public_key = secp256k1.multiply(secp256k1.G, private_key) # 计算公钥\n",
    "\n",
    "print(f\"Private Key: {private_key}\")\n",
    "print(f\"Public Key: {public_key}\")\n",
    "\n",
    "message = \"Hello, blockchain world!\"\n",
    "signature = sign_message(private_key, message) # 签名消息\n",
    "is_valid = verify_signature(message, signature, public_key) # 尝试从签名恢复公钥\n",
    "\n",
    "# 比较原始公钥和恢复的公钥\n",
    "print(f\"Signature valid: {is_valid}\")\n",
    "\n",
    "# 示例输出\n",
    "# Private Key: 100160191408028635805410835424804882729758587641862022398559246101084514055515\n",
    "# Public Key: (94753041202778772959486517607721465828067708966050249355074253521404789962176, 108824044826657285606250531715029407748756362423778933890891533480553307901806)\n",
    "# Signature valid: True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5a2c9f7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Private Key: 98359178994781335595533648854802231427270090895769248482397491373685555850978\n",
      "Public Key: (3661113004864472419130070831996330893639690693841499262022550248113059694488, 16647856845341024716707355890250833951196099189567973816478113518219363325204)\n"
     ]
    }
   ],
   "source": [
    "# bn128 生成公钥\n",
    "from py_ecc.bn128 import bn128_curve\n",
    "import os\n",
    "\n",
    "def generate_bn128_public_key(private_key):\n",
    "    \"\"\"\n",
    "    使用bn_128曲线和给定的私钥生成公钥。\n",
    "    \n",
    "    参数:\n",
    "    private_key (int): 私钥，一个大整数。\n",
    "    \n",
    "    返回:\n",
    "    (int, int): 公钥，bn_128曲线上的点。\n",
    "    \"\"\"\n",
    "    # BN128_G1是bn_128曲线的基点\n",
    "    public_key = bn128_curve.multiply(bn128_curve.G1, private_key)\n",
    "    return public_key\n",
    "\n",
    "# 示例：使用一个随机的私钥\n",
    "private_key = int.from_bytes(os.urandom(32), 'big')\n",
    "\n",
    "# 生成公钥\n",
    "public_key = generate_bn128_public_key(private_key)\n",
    "\n",
    "# 打印结果\n",
    "print(f\"Private Key: {private_key}\")\n",
    "print(f\"Public Key: {public_key}\")\n",
    "\n",
    "# 示例输出\n",
    "# Private Key: 98359178994781335595533648854802231427270090895769248482397491373685555850978\n",
    "# Public Key: (3661113004864472419130070831996330893639690693841499262022550248113059694488, 16647856845341024716707355890250833951196099189567973816478113518219363325204)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f775bbf6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2)\n",
      "((10857046999023057135944570762232829481370756359578518086990519993285655852781, 11559732032986387107991004021392285783925812861821192530917403151452391805634), (8495653923123431417604973247489272438418190587263600148770280649306958101930, 4082367875863433681332203403145435568316851327593401208105741076214120093531))\n",
      "\n",
      "\n",
      "Pairing of points A and B:  (19735667940922659777402175920395455799125563888708961631093487249968872129612, 1976543863057094994989237517814173599120655827589866703826517845909315612857, 19686523416572620016989349096902944934819162198495809257491045534399198954254, 5826646852844954420149583478015267673527445979905768896060072350584178989060, 2064185964405234542610947637037132798744921024553195185441592358018988389207, 8341934863294343910133492936755210611939463215146220944606211376003151106114, 12807669762027938768857302676393862225355612177677457846751491105239425227277, 5741126950795831539169012545403256931813076395529913201048083937620822856065, 11074901068523180915867722424807487877141140784438044188857570704539589417315, 19327019285776193278582429402961044775129507055467003359023290900912857119476, 17306986078986604236447922180440988200852103029519452658980599808670992125088, 13188937242065601189938233945175869194113210620973903647453917247887073581439)\n",
      "\n",
      "\n",
      "Pairing of points G2 and C:  (19735667940922659777402175920395455799125563888708961631093487249968872129612, 1976543863057094994989237517814173599120655827589866703826517845909315612857, 19686523416572620016989349096902944934819162198495809257491045534399198954254, 5826646852844954420149583478015267673527445979905768896060072350584178989060, 2064185964405234542610947637037132798744921024553195185441592358018988389207, 8341934863294343910133492936755210611939463215146220944606211376003151106114, 12807669762027938768857302676393862225355612177677457846751491105239425227277, 5741126950795831539169012545403256931813076395529913201048083937620822856065, 11074901068523180915867722424807487877141140784438044188857570704539589417315, 19327019285776193278582429402961044775129507055467003359023290900912857119476, 17306986078986604236447922180440988200852103029519452658980599808670992125088, 13188937242065601189938233945175869194113210620973903647453917247887073581439)\n",
      "\n",
      "\n",
      "Is pair_A_B == pair_G2_C?  True\n"
     ]
    }
   ],
   "source": [
    "# bn128 双线性配对\n",
    "from py_ecc.bn128 import G1, G2, pairing, add, multiply, eq\n",
    "\n",
    "print(G1)\n",
    "print(G2)\n",
    "print(\"\\n\")\n",
    "\n",
    "a = 69\n",
    "b = 420\n",
    "c = a * b\n",
    "A = multiply(G2, a)\n",
    "B = multiply(G1, b)\n",
    "pair_A_B = pairing(A, B)\n",
    "print(\"Pairing of points A and B: \",pair_A_B)\n",
    "print(\"\\n\")\n",
    "\n",
    "C = multiply(G2, c)\n",
    "pair_G2_C = pairing(C, G1)\n",
    "print(\"Pairing of points G2 and C: \",pair_G2_C)\n",
    "print(\"\\n\")\n",
    "\n",
    "print(\"Is pair_A_B == pair_G2_C? \", pair_A_B == pair_G2_C)\n",
    "\n",
    "# 输出\n",
    "# (1, 2)\n",
    "# ((10857046999023057135944570762232829481370756359578518086990519993285655852781, 11559732032986387107991004021392285783925812861821192530917403151452391805634), (8495653923123431417604973247489272438418190587263600148770280649306958101930, 4082367875863433681332203403145435568316851327593401208105741076214120093531))\n",
    "\n",
    "\n",
    "# Pairing of points A and B:  (19735667940922659777402175920395455799125563888708961631093487249968872129612, 1976543863057094994989237517814173599120655827589866703826517845909315612857, 19686523416572620016989349096902944934819162198495809257491045534399198954254, 5826646852844954420149583478015267673527445979905768896060072350584178989060, 2064185964405234542610947637037132798744921024553195185441592358018988389207, 8341934863294343910133492936755210611939463215146220944606211376003151106114, 12807669762027938768857302676393862225355612177677457846751491105239425227277, 5741126950795831539169012545403256931813076395529913201048083937620822856065, 11074901068523180915867722424807487877141140784438044188857570704539589417315, 19327019285776193278582429402961044775129507055467003359023290900912857119476, 17306986078986604236447922180440988200852103029519452658980599808670992125088, 13188937242065601189938233945175869194113210620973903647453917247887073581439)\n",
    "\n",
    "\n",
    "# Pairing of points G2 and C:  (19735667940922659777402175920395455799125563888708961631093487249968872129612, 1976543863057094994989237517814173599120655827589866703826517845909315612857, 19686523416572620016989349096902944934819162198495809257491045534399198954254, 5826646852844954420149583478015267673527445979905768896060072350584178989060, 2064185964405234542610947637037132798744921024553195185441592358018988389207, 8341934863294343910133492936755210611939463215146220944606211376003151106114, 12807669762027938768857302676393862225355612177677457846751491105239425227277, 5741126950795831539169012545403256931813076395529913201048083937620822856065, 11074901068523180915867722424807487877141140784438044188857570704539589417315, 19327019285776193278582429402961044775129507055467003359023290900912857119476, 17306986078986604236447922180440988200852103029519452658980599808670992125088, 13188937242065601189938233945175869194113210620973903647453917247887073581439)\n",
    "\n",
    "\n",
    "# Is pair_A_B == pair_G2_C?  True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "cc26d294",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Private Key: 56832202591799069674370871859151631253659339730808373097707650526306669655451\n",
      "Public Key: (2672943242084458229690202553507767493858110823696659228443909079159465919837314837610879707240986236828893077890320, 1516123302208562362629191397278119903430202415903098718379575356530260147717671392463098304288800407793122740332702)\n"
     ]
    }
   ],
   "source": [
    "# bls12_381 生成公钥\n",
    "from py_ecc.bls12_381 import bls12_381_curve\n",
    "import os\n",
    "\n",
    "def generate_bn12_381_public_key(private_key):\n",
    "    \"\"\"\n",
    "    使用bn_128曲线和给定的私钥生成公钥。\n",
    "    \n",
    "    参数:\n",
    "    private_key (int): 私钥，一个大整数。\n",
    "    \n",
    "    返回:\n",
    "    (int, int): 公钥，bn_128曲线上的点。\n",
    "    \"\"\"\n",
    "    # BN128_G1是bn_128曲线的基点\n",
    "    public_key = bls12_381_curve.multiply(bls12_381_curve.G1, private_key)\n",
    "    return public_key\n",
    "\n",
    "# 示例：使用一个随机的私钥\n",
    "private_key = int.from_bytes(os.urandom(32), 'big')\n",
    "\n",
    "# 生成公钥\n",
    "public_key = generate_bn12_381_public_key(private_key)\n",
    "\n",
    "# 打印结果\n",
    "print(f\"Private Key: {private_key}\")\n",
    "print(f\"Public Key: {public_key}\")\n",
    "\n",
    "# 示例输出\n",
    "# Private Key: 56832202591799069674370871859151631253659339730808373097707650526306669655451\n",
    "# Public Key: (2672943242084458229690202553507767493858110823696659228443909079159465919837314837610879707240986236828893077890320, 1516123302208562362629191397278119903430202415903098718379575356530260147717671392463098304288800407793122740332702)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b9e402ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507, 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569)\n",
      "((352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160, 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758), (1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905, 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582))\n",
      "\n",
      "\n",
      "Pairing of points A and B:  (559875907953044229256999964908655596470329614681804657067074917348889299656574983763205735263906508658423626306192, 3251387332700024622230711712327939415422447046055926038630362608193945095062996827680637432749053965474170688846803, 1858978301495685148589092187900391308425211794249943939941796868269658435530364461212323465553496690057506398710958, 2821404563389658506867792213698964607416184520400354580766817454079710851304957653749944402097411780097914172680501, 3371394908151563362208243796489511825354821020573987752522791881868987441291678825694507113985550194783443672326288, 2297984649797609740520111469542560058998637859756636710986648527547199594538622957148043186058263511759636104385884, 3480762570907741510541555641785158658308333937734941283300383364697580261225975907843679022209374260264933745191828, 3240728397255321363427476858948130370605249287048803384220203355573990507150386888156524321441752887099266166133108, 2376364160413810038009747479244195484637259359228646277111417852748902100064937901534264975269224589631629799823776, 505616797063036550970852124247959597244795697098930755073121309023649013438395471915981324345265013483679297150493, 283646809217572597374969288842854659843926065997224794730305413934017744924705963601539908633134851567640611976585, 208748941951544416005406635656082534817221797560780462964136211816030039051269393961107822344678318294491041226308)\n",
      "\n",
      "\n",
      "Pairing of points G2 and C:  (559875907953044229256999964908655596470329614681804657067074917348889299656574983763205735263906508658423626306192, 3251387332700024622230711712327939415422447046055926038630362608193945095062996827680637432749053965474170688846803, 1858978301495685148589092187900391308425211794249943939941796868269658435530364461212323465553496690057506398710958, 2821404563389658506867792213698964607416184520400354580766817454079710851304957653749944402097411780097914172680501, 3371394908151563362208243796489511825354821020573987752522791881868987441291678825694507113985550194783443672326288, 2297984649797609740520111469542560058998637859756636710986648527547199594538622957148043186058263511759636104385884, 3480762570907741510541555641785158658308333937734941283300383364697580261225975907843679022209374260264933745191828, 3240728397255321363427476858948130370605249287048803384220203355573990507150386888156524321441752887099266166133108, 2376364160413810038009747479244195484637259359228646277111417852748902100064937901534264975269224589631629799823776, 505616797063036550970852124247959597244795697098930755073121309023649013438395471915981324345265013483679297150493, 283646809217572597374969288842854659843926065997224794730305413934017744924705963601539908633134851567640611976585, 208748941951544416005406635656082534817221797560780462964136211816030039051269393961107822344678318294491041226308)\n",
      "\n",
      "\n",
      "Is pair_A_B == pair_G2_C?  True\n"
     ]
    }
   ],
   "source": [
    "# bls12_381 双线性配对\n",
    "from py_ecc.bls12_381 import G1, G2, pairing, add, multiply, eq\n",
    "\n",
    "print(G1)\n",
    "print(G2)\n",
    "print(\"\\n\")\n",
    "\n",
    "a = 69\n",
    "b = 420\n",
    "c = a * b\n",
    "A = multiply(G2, a)\n",
    "B = multiply(G1, b)\n",
    "pair_A_B = pairing(A, B)\n",
    "print(\"Pairing of points A and B: \",pair_A_B)\n",
    "print(\"\\n\")\n",
    "\n",
    "C = multiply(G2, c)\n",
    "pair_G2_C = pairing(C, G1)\n",
    "print(\"Pairing of points G2 and C: \",pair_G2_C)\n",
    "print(\"\\n\")\n",
    "\n",
    "print(\"Is pair_A_B == pair_G2_C? \", pair_A_B == pair_G2_C)\n",
    "\n",
    "# 输出\n",
    "# (3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507, 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569)\n",
    "# ((352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160, 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758), (1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905, 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582))\n",
    "\n",
    "\n",
    "# Pairing of points A and B:  (559875907953044229256999964908655596470329614681804657067074917348889299656574983763205735263906508658423626306192, 3251387332700024622230711712327939415422447046055926038630362608193945095062996827680637432749053965474170688846803, 1858978301495685148589092187900391308425211794249943939941796868269658435530364461212323465553496690057506398710958, 2821404563389658506867792213698964607416184520400354580766817454079710851304957653749944402097411780097914172680501, 3371394908151563362208243796489511825354821020573987752522791881868987441291678825694507113985550194783443672326288, 2297984649797609740520111469542560058998637859756636710986648527547199594538622957148043186058263511759636104385884, 3480762570907741510541555641785158658308333937734941283300383364697580261225975907843679022209374260264933745191828, 3240728397255321363427476858948130370605249287048803384220203355573990507150386888156524321441752887099266166133108, 2376364160413810038009747479244195484637259359228646277111417852748902100064937901534264975269224589631629799823776, 505616797063036550970852124247959597244795697098930755073121309023649013438395471915981324345265013483679297150493, 283646809217572597374969288842854659843926065997224794730305413934017744924705963601539908633134851567640611976585, 208748941951544416005406635656082534817221797560780462964136211816030039051269393961107822344678318294491041226308)\n",
    "\n",
    "\n",
    "# Pairing of points G2 and C:  (559875907953044229256999964908655596470329614681804657067074917348889299656574983763205735263906508658423626306192, 3251387332700024622230711712327939415422447046055926038630362608193945095062996827680637432749053965474170688846803, 1858978301495685148589092187900391308425211794249943939941796868269658435530364461212323465553496690057506398710958, 2821404563389658506867792213698964607416184520400354580766817454079710851304957653749944402097411780097914172680501, 3371394908151563362208243796489511825354821020573987752522791881868987441291678825694507113985550194783443672326288, 2297984649797609740520111469542560058998637859756636710986648527547199594538622957148043186058263511759636104385884, 3480762570907741510541555641785158658308333937734941283300383364697580261225975907843679022209374260264933745191828, 3240728397255321363427476858948130370605249287048803384220203355573990507150386888156524321441752887099266166133108, 2376364160413810038009747479244195484637259359228646277111417852748902100064937901534264975269224589631629799823776, 505616797063036550970852124247959597244795697098930755073121309023649013438395471915981324345265013483679297150493, 283646809217572597374969288842854659843926065997224794730305413934017744924705963601539908633134851567640611976585, 208748941951544416005406635656082534817221797560780462964136211816030039051269393961107822344678318294491041226308)\n",
    "\n",
    "\n",
    "# Is pair_A_B == pair_G2_C?  True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a84b3f88",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "Expected an int or FQ object, but got object of type <class 'py_ecc.fields.bls12_381_FQ2'>",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/xz/sj6gs0f150n67pbx3mg32v3c0000gn/T/ipykernel_62883/1937742263.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpairing\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mG1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mG2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/usr/local/lib/python3.7/site-packages/py_ecc/bls12_381/bls12_381_pairing.py\u001b[0m in \u001b[0;36mpairing\u001b[0;34m(Q, P)\u001b[0m\n\u001b[1;32m    107\u001b[0m \u001b[0;31m# Pairing computation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    108\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mpairing\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mQ\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mPoint2D\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mFQ2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mP\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mPoint2D\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mFQ\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mFQ12\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 109\u001b[0;31m     \u001b[0;32massert\u001b[0m \u001b[0mis_on_curve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mQ\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    110\u001b[0m     \u001b[0;32massert\u001b[0m \u001b[0mis_on_curve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mP\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    111\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mmiller_loop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtwist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mQ\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcast_point_to_fq12\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mP\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.7/site-packages/py_ecc/bls12_381/bls12_381_curve.py\u001b[0m in \u001b[0;36mis_on_curve\u001b[0;34m(pt, b)\u001b[0m\n\u001b[1;32m     65\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     66\u001b[0m     \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 67\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m3\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     68\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     69\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.7/site-packages/py_ecc/fields/field_elements.py\u001b[0m in \u001b[0;36m__eq__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m    166\u001b[0m             raise TypeError(\n\u001b[1;32m    167\u001b[0m                 \u001b[0;34m\"Expected an int or FQ object, but got object of type {}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 168\u001b[0;31m                 \u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    169\u001b[0m             )\n\u001b[1;32m    170\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: Expected an int or FQ object, but got object of type <class 'py_ecc.fields.bls12_381_FQ2'>"
     ]
    }
   ],
   "source": [
    "pairing(G1, G2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b99237ea",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
